
String[] menupoints = {"Jouer","Options","Instructions"};
var activeMenupoint =0;
int TIME_PER_MENUPOINT = 1000*3;
int timeBeginMenupoint = millis ();
int isActiveMM = 0;
bool alreadyPressedOnce = false;

// ---------- ----------
// code specific to the Main Menu state
// ---------- ----------

void drawMainMenu()
{
	if ( justCameIn )
	{
		alreadyPressedOnce = false;
		justCameIn = 0;
	}
	if (isActiveMM == 0) {
		setActiveMainMenu();
	}
	background ( 125 );
	fill ( 255 );
	
	//float timeEllapsed = millis () - timeStartGame;
	//text ( timeEllapsed, 30, 100 );
	if ( alreadyPressedOnce == false )
	{
		setActive(millis () - timeBeginMenupoint);
	}
	buildMenu();
	//println("Width: " + width + "; Height: " + height);
}

void setActiveMainMenu() {
	isActiveMM = 1;
	timeBeginMenupoint = millis ();
	play_multi_sound("menu" + (activeMenupoint+1));
}

void buildMenu() {
	for (int i = 0; i < menupoints.length();i++) {
		// Set color to black
		if (activeMenupoint == i) {
			fill( 255, 0, 0 );  
		} else {
			fill( 0, 0, 0 );   
		}
		strokeWeight(-1);
		rect(width/3,height/3+i*50,width/3,40);
		strokeWeight(3);
		stroke(120);
		fill ( 180 );
		textAlign(CENTER);
		PFont fontA = loadFont("arial");
        textFont(fontA, 24);
		text ( menupoints[i], width/3+10, height/3+i*50+10,width/3-10,35);
	}
}

void setActive(float timeEllapsed) {
		
	if ( timeEllapsed-TIME_PER_MENUPOINT > 0) {
		activeMenupoint= (activeMenupoint+1) % menupoints.length();
		play_multi_sound("menu" + (activeMenupoint+1));
		timeBeginMenupoint = millis();
	}
	//println((int)(timeEllapsed/TIME_PER_MENUPOINT) + "; " + activeMenupoint);
	
	
}

void keyPressedMainMenu ()
{
	alreadyPressedOnce = true;
	if( keyCode == ENTER || keyCode == 32 ) {
		if (activeMenupoint == 0) {
			state = 3;
			justCameIn = 1;
		} else if (activeMenupoint == 1) {
			state = 2;
			justCameIn = 1;
		} else if (activeMenupoint == 2) {
			state=5;
			justCameIn = 1;
		}
		//println("Set state to: " + state);
		isActiveMM = 0;
		/*timeBeginMenupoint_opt = millis();
		activeMenupoint_opt = 0;
		play_multi_sound("option" + (activeMenupoint_opt+1));*/

	} else if ( keyCode == UP ) {
			activeMenupoint -= 1;
			if (activeMenupoint < 0) {
				activeMenupoint = menupoints.length()-1;
			}
			timeBeginMenupoint = millis();
			play_multi_sound("menu" + (activeMenupoint+1));
	} else if ( keyCode == DOWN ) {
			activeMenupoint += 1;
			if (activeMenupoint >= menupoints.length()) {
				activeMenupoint = 0;
			}
			timeBeginMenupoint = millis();
			play_multi_sound("menu" + (activeMenupoint+1));
	}
	
}
